Bring back _gtk_tree_view_column_get_cell_at_pos
authorKristian Rietveld <kris@gtk.org>
Sun, 5 Dec 2010 17:18:36 +0000 (18:18 +0100)
committerKristian Rietveld <kris@gtk.org>
Sun, 5 Dec 2010 17:18:36 +0000 (18:18 +0100)
The function has been re-implemented around GtkCellArea.  This commits
also brings back the invocation of this function in
gtk_tree_view_button_press().  I shouldn't have removed this.

gtk/gtktreeview.c
gtk/gtktreeviewcolumn.c

index 2f2d5ce1fd2536616ba32009b4bf246fc242da0f..a2f3846f0471b724c876d246259b629a65472ca3 100644 (file)
@@ -3180,11 +3180,17 @@ gtk_tree_view_button_press (GtkWidget      *widget,
        */
       if (event->type == GDK_BUTTON_PRESS)
         {
+          GtkCellRenderer *focus_cell;
+
           if ((event->state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
             tree_view->priv->ctrl_pressed = TRUE;
           if ((event->state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
             tree_view->priv->shift_pressed = TRUE;
 
+          focus_cell = _gtk_tree_view_column_get_cell_at_pos (column, event->x - background_area.x);
+          if (focus_cell)
+            gtk_tree_view_column_focus_cell (column, focus_cell);
+
           if (event->state & GDK_CONTROL_MASK)
             {
               gtk_tree_view_real_set_cursor (tree_view, path, FALSE, TRUE);
index bf1679e3b58cc8761f2e7258e1a0553653fcefc9..429ed577fb94b22967776aa27bb54c88ffec2f7b 100644 (file)
@@ -1466,6 +1466,40 @@ _gtk_tree_view_column_get_edited_cell (GtkTreeViewColumn *column)
   return gtk_cell_area_get_edited_cell (priv->cell_area);
 }
 
+GtkCellRenderer *
+_gtk_tree_view_column_get_cell_at_pos (GtkTreeViewColumn *column,
+                                       gint               x)
+{
+  GList *list;
+  GList *cell;
+  GtkCellRenderer *match = NULL;
+  GtkTreeViewColumnPrivate *priv = column->priv;
+
+  list = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (column));
+  for (cell = list; cell; cell = cell->next)
+    {
+      GdkRectangle zero_cell_area = { 0, };
+      GdkRectangle allocation;
+
+      gtk_cell_area_get_cell_allocation (priv->cell_area,
+                                         priv->cell_area_context,
+                                         priv->tree_view,
+                                         cell->data,
+                                         &zero_cell_area,
+                                         &allocation);
+
+      if (allocation.x <= x && x <= allocation.x + allocation.width)
+        {
+          match = cell->data;
+          break;
+        }
+    }
+
+  g_list_free (list);
+
+  return match;
+}
+
 /* Public Functions */